<div class="page-breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="fa fa-home"></i>
            <a href="#">Home</a>
        </li>
        <li>
            <a href="#">系统设置</a>
        </li>
        <li class="active">菜单管理</li>
    </ul>
</div>
<!-- Page Body -->
<div class="page-body">
    <div class="row">
        <div class="col-xs-12 col-md-12">
            <div class="widget">
                <div class="widget-header bordered-bottom bordered-blue">
                    <span class="widget-caption">系统菜单列表</span>
                </div>
                <div class="widget-body">
                    <div class="table-toolbar">
                        <a id="editabledatatable_new" href="#!system/menu/menu-add.html" class="btn btn-default">新建菜单</a>
                        <div class="btn-group pull-right">
                            <a class="btn btn-default" href="javascript:void(0);">Tools</a>
                            <a class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="javascript:void(0);"><i class="fa fa-angle-down"></i></a>
                            <ul class="dropdown-menu dropdown-default">
                                <li>
                                    <a href="javascript:void(0);">Action</a>
                                </li>
                                <li>
                                    <a href="javascript:void(0);">Another action</a>
                                </li>
                                <li>
                                    <a href="javascript:void(0);">Something else here</a>
                                </li>
                                <li class="divider"></li>
                                <li>
                                    <a href="javascript:void(0);">Separated link</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <table id="dt_basic" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th></th>
                            <th data-class="phone,tablet">ID</th>
                            <th data-class="expand">名称</th>
                            <th data-hide="phone">请求地址</th>
                            <th data-hide="phone,tablet">菜单类型</th>
                            <th data-hide="phone">操作</th>
                        </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

</div>
<script type="application/javascript">

    $(function(){
        var oTable = $('#dt_basic').dataTable({
            serverSide: true,
            orderMulti: false,
            "sDom": "Tflt<'row DTTTFooter'<'col-sm-6'i><'col-sm-6'p>>",
            "oTableTools": {
                "aButtons": []
            },
            "language": {
                "search": "",
                "sLengthMenu": "_MENU_",
                "oPaginate": {
                    "sPrevious": "Prev",
                    "sNext": "Next"
                }
            },
            columns: [
                { "data": "id" , "bSortable": false, "aTargets": [0]},
                { "data": "id" },
                { "data": "name" },
                { "data": "url" },
                { "data": "menuDef" },
                { "data": "id" ,
                    "render":function(data, type, full, meta){
                        var tmp = '<a href="#" class="btn btn-info btn-xs edit"><i class="fa fa-edit"></i> Edit</a> <a href="#" class="btn btn-danger btn-xs delete"><i class="fa fa-trash-o"></i> Delete</a>';
                                /*'<a class="btn btn-info btn-xs edit" href="javascript:alert(&quot;'+data+'&quot;)"><i class="fa fa-trash-o"></i> 删除</a>'
                                +'<a class="btn btn-danger btn-xs delete" href="javascript:alert(&quot;'+data+'&quot;)"><i class="fa fa-edit"></i> 修改</a>';*/
                        return tmp;
                    }
                }
            ],
            ajax: function (data, callback, settings) {
                var param = {};
                param.limit = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                param.start = data.start;//开始的记录序号
                param.page = (data.start / data.length) + 1;//当前页码
                param.requestUrl=$('#requestUrl').val();

                $.ajax({
                    type: "GET",
                    url: "http://115.28.66.183:8080/ibsm-system/rest/v1/sys/menu/"+param.page+"/"+param.limit,
                    cache: false, //禁用缓存
                    data: param, //传入组装的参数
                    dataType: "json",
                    success: function (content) {
                        var result = content.result;
                        if(null != content.result){
                            var returnData = {};
                            returnData.draw=result.content;//这里直接自行返回了draw计数器,应该由后台返回
                            returnData.recordsTotal = result.totalSize;//返回数据全部记录
                            returnData.recordsFiltered = result.totalSize;//后台不实现过滤功能，每次查询均视作全部结果
                            returnData.data = result.content;//返回的数据列表
                            callback(returnData);
                        }
                    }
                });
            },
            "fnCreatedRow": function(nRow, aData, iDataIndex) {
                return $('td:eq(0)', nRow).html('<i class="fa fa-plus-square-o row-details"></i>');
            }
        });

        $('#dt_basic').on('click', ' tbody td .row-details', function () {
            var nTr = $(this).parents('tr')[0];
            if (oTable.fnIsOpen(nTr)) {
                $(this).addClass("fa-plus-square-o").removeClass("fa-minus-square-o");
                oTable.fnClose(nTr);
            }else {
                $(this).addClass("fa-minus-square-o").removeClass("fa-plus-square-o");;
                oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details');
            }
        });
    });

    function fnFormatDetails(oTable, nTr) {
        var aData = oTable.fnGetData(nTr);
        var sOut = '<table>';
        sOut +='		<tr><td>菜单类型:</td><td>'+aData.menuDef+'</td></tr> ';
        sOut +='		<tr><td>访问地址:</td><td>'+aData.url+'</td></tr> ';
        sOut +='		<tr><td>详情:</td><td>'+aData.note+'</td> </tr>';
        sOut +='		<tr><td>上级菜单:</td><td></td></tr> ';
        sOut +='</table> ';
        return sOut;
    }
</script>